﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;
using System;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 物料配置下发配置
    /// </summary>
    public partial class MaterielSortingIssued : BusEntity
    {
        /// <summary>
        /// 分拣配置编号
        /// </summary>
        public string SortingConfigId { set; get; }

        /// <summary>
        /// 顺序号
        /// </summary>
        public int SequenceIndex { set; get; }

        /// <summary>
        /// 配置下发地址(叶片抓取顺序，值为料位电气编码)
        /// </summary>
        public string CollectorAddress { set; get; }
    }

    public partial class MaterielSortingIssued : BusEntity
    {
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class MaterielSortingIssuedTypeConfig : BusEntityTypeConfig<MaterielSortingIssued>, IEntityTypeConfiguration<MaterielSortingIssued>
    {
        public override void Configure(EntityTypeBuilder<MaterielSortingIssued> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.SortingConfigId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.SequenceIndex).IsRequired();
            builder.Property(p => p.CollectorAddress).HasMaxLength(EntityDefinition.DefMiddleColLen).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("物料配置下发配置");
            builder.Property(p => p.SortingConfigId).HasComment("分拣配置编号");
            builder.Property(p => p.SequenceIndex).HasComment("顺序号");
            builder.Property(p => p.CollectorAddress).HasComment("配置下发地址");
            #endregion

            #region 种子数据
            for (var idy = 1; idy < 11; idy++)
            {
                for (var idx = 1; idx < 51; idx++)
                {
                    if (idy < 10)
                    {
                        builder.HasData(new MaterielSortingIssued()
                        {
                            Id = Guid.NewGuid().ToString("n"),
                            SortingConfigId = string.Format("MSC_0{0}", idy),
                            SequenceIndex = idx,
                            CollectorAddress = string.Format("M{0}G{1}_VaneGrabIndex",idy.ToString().PadLeft(2,'0'), idx.ToString().PadLeft(2, '0'))
                        });
                    }
                    else
                    {
                        builder.HasData(new MaterielSortingIssued()
                        {
                            Id = Guid.NewGuid().ToString("n"),
                            SortingConfigId = string.Format("MSC_{0}", idy),
                            SequenceIndex = idx,
                            CollectorAddress = string.Format("M{0}G{1}_VaneGrabIndex", idy.ToString().PadLeft(2, '0'), idx.ToString().PadLeft(2, '0'))
                        });
                    }
                }
            }
            #endregion
        }
    }
}
